package com.acme.entity;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.validation.groups.Default;

import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Indexed;
import org.hibernate.validator.constraints.NotBlank;

import com.acme.entity.Claim.UserValidation;
import com.acme.entity.security.UserAuthority;

@Entity
@Indexed
@Table(name="users")
public class User {
	
	@Id @GeneratedValue
	@Column(name = "id")
	private int userID;
	
	@Column(name = "username")
	@Field
	private String username;
	
	@Column(name = "password")
	@Field
	private String password;
	
	@Column(name = "email")
	@Field
	private String email;
	
	@Column(name = "resetHash")
	private String resetHash;
	
	@Column(name = "enabled")
	@Field
	private boolean enabled;
	
	@Column(name = "fName")
	@Field
	@NotBlank (message="Cannot be blank.", groups = {Default.class, UserValidation.class})
	@Size(max=20, message="Cannot exceed 20 characters.", groups = {Default.class, UserValidation.class})
	private String fName;
	
	@Column(name = "lName")
	@Field
	@NotBlank (message="Cannot be blank.", groups = {Default.class, UserValidation.class})
	@Size(max=20, message="Cannot exceed 20 characters.", groups = {Default.class, UserValidation.class})
	private String lName;
	
	@Column(name = "birthday")
	@Field
	@NotBlank (message="Cannot be empty.", groups = {Default.class, UserValidation.class})
	private String birthday;
	
	@Column(name = "gender")
	@Field
	@NotNull (message="Cannot be blank.", groups = {Default.class, UserValidation.class})
	private String gender;

	@Column(name = "SSN")
	@Field
	private String SSN;
	
	@Column(name = "accessType")
	@Field
	private String accessType;
	
	@Column(name = "insuranceNumber")
	@Field
	@NotBlank (message="Cannot be blank.", groups = {Default.class, UserValidation.class})
	@Size(max=20, message="Cannot exceed 20 characters.", groups = {Default.class, UserValidation.class})
	private String insuranceNumber;
	
	@OneToMany(mappedBy = "user")
	private List<Claim> claims;
	
	@OneToMany(mappedBy = "user", fetch = FetchType.EAGER)
	private List<UserAuthority> roles;
	
	@Column(name = "address")
	@Field
	private String address;
	
	@Column(name = "city")
	@Field
	private String city;
	
	@Column(name = "state")
	@Field
	private String state;
	
	@Column(name = "zip")
	@Field
	private int zipcode;
	
	
	public User() {
	}

	public User(int userID, String username, String password, String fName,
			String lName, String birthday, String sSN, String gen, List<Claim> claims,
			String accessType, String insuranceNumber) {

		super();
		this.userID = userID;
		this.username = username;
		this.password = password;
		this.fName = fName;
		this.lName = lName;
		this.birthday = birthday;
		SSN = sSN;
		this.gender = gen;
		this.claims = claims;
		this.accessType = accessType;
		this.insuranceNumber = insuranceNumber;
	}
	public User(String fName, String lName, String birthday, String insuranceNumber, String sSN, String username, String password){
		super();
		this.fName = fName;
		this.lName = lName;
		this.insuranceNumber = insuranceNumber;
		this.birthday = birthday;
		this.SSN = sSN;
		this.username = username;
		this.password = password;
	}

	public int getUserID() {
		return userID;
	}

	public void setUserID(int userID) {
		this.userID = userID;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getfName() {
		return fName;
	}

	public void setfName(String fName) {
		this.fName = fName;
	}

	public String getlName() {
		return lName;
	}

	public void setlName(String lName) {
		this.lName = lName;
	}

	public String getBirthday() {
		return birthday;
	}

	public void setBirthday(String birthday) {
		this.birthday = birthday;
	}

	public String getSSN() {
		return SSN;
	}

	public void setSSN(String sSN) {
		SSN = sSN;
	}


	public String getGender() {
		return gender;
	}

	public void setGender(String gender) {
		this.gender = gender;
	}
	
	public List<Claim> getClaims() {
		return claims;
	}

	public void setClaims(List<Claim> claims) {
		this.claims = claims;
	}

	public String getAccessType() {
		return accessType;
	}

	public void setAccessType(String accessType) {
		this.accessType = accessType;
	}

	public String getInsuranceNumber() {
		return insuranceNumber;
	}

	public void setInsuranceNumber(String insuranceNumber) {
		this.insuranceNumber = insuranceNumber;
	}

	public static Object getUserByID(int i) {
		// TODO Auto-generated method stub
		return null;
	}
	
	public boolean isEnabled() {
		return enabled;
	}

	public void setEnabled(boolean enabled) {
		this.enabled = enabled;
	}
	
	public List<UserAuthority> getRoles() {
		return roles;
	}
	
	public String getResetHash() {
		return resetHash;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public void setResetHash(String resetHash) {
		this.resetHash = resetHash;
	}
	
	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public String getState() {
		return state;
	}

	public void setState(String state) {
		this.state = state;
	}

	public int getZipcode() {
		return zipcode;
	}

	public void setZipcode(int zipcode) {
		this.zipcode = zipcode;
	}

	@Override
	public String toString() {
		return "User [userID=" + userID + ", username=" + username
				+ ", password=" + password + ", enabled=" + enabled
				+ ", fName=" + fName + ", lName=" + lName + ", birthday="
				+ birthday + ", gender=" + gender + ", SSN=" + SSN
				+ ", accessType=" + accessType + ", insuranceNumber="
				+ insuranceNumber + ", claims=" + claims + "]";
	}
	
}
